package com.xyw.code.study202007281.service;

import com.xyw.code.study202007281.entity.Order;
import com.xyw.code.study202007281.handler.MobileOrderHandler;
import com.xyw.code.study202007281.handler.OrderHandler;
import com.xyw.code.study202007281.handler.PcOrderHandler;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: xuyiwei
 * Date: 2020/7/28
 * Time: 下午10:55
 * Email: 1328312923@qq.com
 * Description: No Description
 **/
@Service
public class OrderServiceImpl {
    Map<String, OrderHandler> orderHandlerMap = new HashMap<>();

    @PostConstruct
    public void generator(){
        orderHandlerMap.put("pc",new PcOrderHandler());
        orderHandlerMap.put("mobile",new MobileOrderHandler());
    }

    public String hander(Order order){
        OrderHandler orderHandler = orderHandlerMap.get(order.getSource());
       return orderHandler.handler(order);
    }
}
